package com.temp.move;

import java.io.File;

public class ChangeFileName {
    public static void main(String []args){
        try{
            readfile("F:\\space\\imsp_hg_logistics\\blade-logistics-service\\blade-logistics-core\\src\\main\\java\\org\\springblade\\logistics\\xk");
        }catch (Exception ex){
            ex.printStackTrace();
        }

    }
    public static void readfile(String filepath) throws  Exception {
        try {
            File file = new File(filepath);
            if (!file.isDirectory()) {
                System.out.println("文件");
                System.out.println("path=" + file.getPath());
                System.out.println("absolutepath=" + file.getAbsolutePath());
                System.out.println("name=" + file.getName());
            } else if (file.isDirectory()) {
                String[] filelist = file.list();
                System.out.println("文件夹:" + filelist.length + "个文件");
                String suffix = null;
                String prefix = null;
                for (int i = 0; i < filelist.length; i++) {
                    File readfile = new File(filepath + "\\" + filelist[i]);
                    System.out.print(i + "---{");
                    if (!readfile.isDirectory()) {
                        //修改文件名称
                        rename("Xk", readfile);
                    } else if (readfile.isDirectory()) {
                        readfile(filepath + "\\" + filelist[i]);
                    }
                    System.out.println("}");
                }
            }
        } catch ( Exception e) {
            System.out.println("readfile()   Exception:" + e.getMessage());
        }
    }

    private static void rename(String prefix, File readfile) {
        File saveFile = new File(readfile.getParentFile().getAbsolutePath()+"/" + prefix + readfile.getName());
        System.out.print("---" + readfile.renameTo(saveFile));
    }

}
